using GEM.Api.Dto;
using GEM.Application.Common;
using GEM.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace GEM.Api.Controllers;

[ApiController]
[Route("api/[controller]")]
public class AuthController : ControllerBase
{
    private readonly AuthService _authService;
    //依赖注入
    public AuthController(AuthService authService)
    {
        _authService = authService;
    }

    //用户注册
    [HttpPost("register")]
    public async Task<IActionResult> Register(UserRegisterDto userRegisterDto)
    {
        var result = await _authService.RegisterAsync(userRegisterDto.Username, userRegisterDto.Password);
        return Ok(result);
    }

    [HttpPost("login")]
    public async Task<IActionResult> Login(UserRegisterDto userRegisterDto)
    {
        var isTrue = await _authService.LoginAsync(userRegisterDto.Username, userRegisterDto.Password);
        return Ok(isTrue);
    }

}